<?php

use yii\helpers\Url;
use yii\bootstrap\ActiveForm;

$this->context->layout = false;
?>

<?php
$form = ActiveForm::begin([
    'id' => 'm-authorization-form',
    'options' => [
        'class' => 'form-horizontal'
    ]
]);
?>
<?php
//使用率
echo $this->render("@app/views/public/useRate.php")
?>
<div class="m_form_box">
    <select id="authorizationa" multiple="multiple" name="authorization[]" data-placeholder="请选择..."></select>
    <button type="button" class="k-button k-button-icontext m_r_btn" id="m-authorization-submit"
            style="margin-top:30px;">&nbsp;提&nbsp;交&nbsp;
    </button>
</div>
<?php ActiveForm::end(); ?>
<script>
    $(function () {
        $.ajax({
            url: "<?=Url::to(['/salary/pickperformance/default/getagentstaff']) ?>",
            dataType: "json",
            success: function (d) {
                var olSelectId = JSON.parse('<?=json_encode($obtain) ?>');
                var _html = "";
                for (var i = 0; i < d.length; i++) {
                    var strSelect = olSelectId.indexOf(d[i].user_id) >= 0 ? "selected" : "";
                    _html += '<option value=' + d[i].user_id + ' ' + strSelect + '>' + d[i].username + '</option>';
                }
                $("#authorizationa").append(_html);
                $("#authorizationa").kendoMultiSelect().data("kendoMultiSelect");
            }
        });
        $("#m-authorization-submit").click(function () {
            var _this = $(this);
            $("#m-authorization-submit").prop("disabled", true);
            _this.parents("#m-authorization-form").ajaxSubmit({
                url: "<?=Url::to(['setagent']) ?>",
                data: {id: "<?=$id ?>"},
                type: "POST",
                dataType: "json",
                success: function (redata) {
                    if (redata.status == 1) {
                        var _staffWindow = agentOpenWindow.data('kendoWindow');
                        _staffWindow.refresh();
                        _staffWindow.close();
                    } else {
                        $("#m-authorization-submit").prop("disabled", false);
                        layer.msg(redata.msg, {icon: 5});
                    }
                }
            })
        });
    })
</script>